package Canvas;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Ellipse2D;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class ScrollPaneCanvas extends JFrame
{
    class Canvas extends JPanel
    {
        public Canvas()
        {
            setSize(getPreferredSize());
            Canvas.this.setBackground(Color.white);
        }

        public Dimension getPreferredSize()
        {
            return new Dimension(800, 600);
        }

        public void paintComponent(Graphics g)
        {
            super.paintComponent(g);
            Graphics2D g2d = (Graphics2D) g;
            Ellipse2D ellipse = new Ellipse2D.Double(0, 0, 100, 100);
            g2d.setColor(Color.cyan);
            g2d.translate(10, 10);
            g2d.draw(ellipse);
            g2d.fill(ellipse);
        }
    }

    public ScrollPaneCanvas()
    {
        super("Swing Application");
        setSize(300, 300);
        getContentPane().add(new JScrollPane(new Canvas()));
    }

    public static void main(String[] args)
    {
        ScrollPaneCanvas canvas = new ScrollPaneCanvas();
        canvas.show();
    }
}
